package States 
{
	import nl.jorisdormans.phantom2D.core.Composite;
	import nl.jorisdormans.phantom2D.objects.GameObject;
	import nl.jorisdormans.phantom2D.ai.statemachines.State;
	import nl.jorisdormans.phantom2D.ai.statemachines.StateMachine;
	
	/**
	 * ...
	 * @author Sebastiaan
	 * 
	 * This state makes the player go faster when the FastPowerup is collected
	 */
	public class FastState extends State
	{
		private var timer : Number;							//Variable used for the timer
		private var delay : Number;							//Variable used for the timer
		
		private var Force : int;							//Variable used to calculate new random force
		private var oldForce : int;							
		private var minForce : uint = 350;					
		private var maxForce : uint = 500;
		
		public function FastState() 
		{
			Force = Math.floor(Math.random() * (1 + maxForce - minForce)) + minForce;				//calculates a random force between 350 and 500
			oldForce = Player.getForce();															//sets the oldforce to oldforce variable
		}
		
		override public function onActivate():void 
		{
			super.onActivate();
			this.timer = 4 + Math.random() * 8;
			this.delay = 1.0;
			Player.setForce(Force);																	//sets the new force to the player
		}
		
		//If the timer is done the oldforce will be set on the player
		override public function update(elapsedTime:Number):void 
		{
			super.update(elapsedTime);
			
			if (timer > 0) 
			{
				if (delay <= 0)
				{
					delay = 1.0
				}
				
				delay -= elapsedTime;
				timer -= elapsedTime;
			}
			else
			{
				Player.setForce(oldForce);
				this.stateMachine.popState();
			}
		}
	}
}